/**
 *
 * @file main.c
 *
 * @brief This file contains main function of TSAR
 *
 * $Id: main.c 116 2009-01-15 07:23:52Z henri.doreau $
 */

/*
 * This file is part of Tsar.
 *
 * Tsar is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tsar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tsar.  If not, see <http://www.gnu.org/licenses/>.
 */



#include <utils.h>      /* Several various utilies */
#include <options.h>    /* Command line parsing */
#include <tsar.h>       /* Tsar core */
#include <webserver.h>


void usage( char * _progname );



int main( int argc, char **argv )
{
    int retVal;
    opt_t o;

    /* Parse command line */
    if ( tsar_get_options( argc, argv, &o ) )
    {
        usage( argv[0] );
        retVal = 1;
    }
    /* Start services */
    else if ( tsar_start_session( &o ) )
    {
        printf( "Quitting!!\n" );
        retVal = 2;
    }
    else
    {
        /* Success case */
        retVal = 0;
    }

    return retVal;
}


void usage( char * _progname )
{
    fprintf( stderr, 
        "Usage : %s [options]\n"
        "Where options are :\n\n"
        "  -I, --interface <network interface>       Force tsar to watch this network interface\n"
        "  -o, --output <filename>                   Output filename\n"
        "  -t, --timeout <milliseconds>              update our network dump every <milliseconds>\n"
        "  -p, --http-port <port>                    bind http server on supplied port\n"
        "  -L, --load-file <filename>                Do not start built-in sniffer, load <filename> instead,<filename> is a pcap file\n"
        "  -f, --filter <bpf expression>             Apply bpf filter on the sniffer to reduce network dump' size\n"
        "      --trace-opt                           Print out a summarry of enabled options after command line parsing\n"
        "      --promisc                             Enable promiscuous mode on selected interface\n"
        "      --debug                               Enable debug mode (insane verbosity)\n"
        "  -v                                        Increase the verbosity level. You can chain up to %d -v to reach the maximum verbosity level\n"
        "  -V, --version                             Show the program version and exit\n"
        "  -h, --help                                print out this help screen\n",
          _progname,
          MAX_VERBOSITY_LEVEL );
}

